package com.woniuxy.util;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Supplier;

/**
 * @Description BeanCopyUtil的工具类泛型转换list集合
 * @Author Joker
 * @Date 17:19 2021/5/13
 * @Param
 * @Return
 */


public class BeanCopyUtil extends BeanUtils {
    /**
     * @Description
     * @Author Joker
     * @Date 17:19 2021/5/13
     * @Param [sources, target]sources:源文件,target复制文件
     * @Return java.util.List<T> 返回list泛型
     */
    public static <S,T> List<T> copyListProperties(List<S> sources, Supplier<T> target){
        List<T> list = new ArrayList<>(sources.size());
        for(S source:sources){
            T t = target.get();
            copyProperties(source,t);
            list.add(t);
        }
        return list;
    }
}
